package com.loveprogrammer.eternity.skill.support.skills;

import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.common.Tuple;
import com.loveprogrammer.eternity.skill.support.states.MagicIncrState;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @version 1.0.0
 * @description: 冥想
 * @author: eric
 * @date: 2022-08-11 16:49
 **/
public class SkillMeditation extends AbstractSkill {

    public SkillMeditation(int id, int baseInterval, int level, int order, int maxLevel, String name, String desc) {
        super(id, baseInterval, level, order, maxLevel, name, desc);
    }

    @Override
    public boolean check(Character character) {
        return true;
    }

    @Override
    public int opportunityPassive() {
        // 主动技能
        return 0;
    }

    @Override
    public boolean checkLevelUp(int characterLevel) {
        // 每三级升一级
        if (characterLevel % 4 == 0) {
            return true;
        }
        return false;
    }

    /***
     * 发动技能
     **/
    @Override
    public Tuple<String, List<Character>> skillLaunch(Character character,
                                                      List<? extends Character> attack,
                                                      List<? extends Character> defences) {
        Tuple<String, List<Character>> result = new Tuple<>();

        List<Character> characters = new ArrayList<>();

        // 增加法力 持续10s钟，同时增加一个状态
        int power = getHarm(character);
        StringBuilder builder = new StringBuilder();
        builder.append(character.getName()).append("(").append(character.getCurrentHp()).append("/")
                .append(character.getHpMax()).append(")").append(" 使用技能[")
                .append(getName()).append(" ").append(getLevel()).append("级】增加了自身法力 ").append(power).append("点,持续持续10s");

        // 冥想
        MagicIncrState magicIncrState = new MagicIncrState(character, defences, power);
        character.acquireState(magicIncrState,10);
        character.setMagic(character.getMagic() + power);
        // setTimeTask(magicIncrState, 20);
        timer.newTimeout(timeout -> magicIncrState.reset(), 10, TimeUnit.SECONDS);
        result.setValue(characters);
        result.setKey(builder.toString());
        return result;
    }

    @Override
    protected int computeHarm(Character character) {
        return (int) (character.getMagic() * 0.5 + getLevel() * 50);
    }

    @Override
    protected int computeSecondHarm(Character character) {
        return 0;
    }
}
